﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using RegattaStarter.Models;
using System.IO.IsolatedStorage;

namespace RegattaStarter
{
    public partial class Flags : PhoneApplicationPage
    {

        public string flagNumber;
        private static IsolatedStorageSettings userSettings = IsolatedStorageSettings.ApplicationSettings;

        public Flags()
        {
            InitializeComponent();
            FillListBox();
	    }

        protected override void  OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            string navigationMessage;
            NavigationContext.QueryString.TryGetValue("Flagnumber", out navigationMessage);
            switch (navigationMessage) 
            {
                case "1":
                    flagNumber = "1";
                    break;
                case "2":
                    flagNumber = "2";
                    break;
                case "3":
                    flagNumber = "3";
                    break;
                default:
                    flagNumber = "1";
                    break;
            }
        }
 
	    private void FillListBox()
	    {
            FlagList listofflags = new FlagList();
            listBox1.ItemsSource = listofflags;
	    }

        private void ButtonList_click(object sender, RoutedEventArgs e)
        {
          Button btn = (Button)sender;
          string pathFlag = "/Images/Flags/" + btn.CommandParameter.ToString() + ".png";

          try 
          {
              switch (flagNumber) 
              { 
                  case "1":
                        userSettings.Remove("firstFlagSettingCustom");
                        userSettings.Add("firstFlagSettingCustom", pathFlag);
                      break;
                  case "2":
                         userSettings.Remove("secondFlagSettingCustom");
                         userSettings.Add("secondFlagSettingCustom", pathFlag);
                      break;
                  case "3":
                         userSettings.Remove("thirdFlagSettingCustom");
                         userSettings.Add("thirdFlagSettingCustom", pathFlag);
                      break;
              }

              userSettings.Save();
              NavigationService.GoBack();
          }
          catch (Exception ex) 
          {
          }
        }
    }
}